/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.admin.controller;

import com.admin.model.EventInfoFacadeLocal;
import com.admin.model.EventLibraryFacadeLocal;
import com.common.json.JsonModel;
import com.entities.EventInfo;
import com.entities.EventLibrary;
import java.util.Date;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import org.json.simple.JSONObject;

/**
 *
 * @author Tuan Long
 */
@Stateless
public class UpdateEventEJB implements UpdateEventEJBRemote {
    @EJB
    private EventInfoFacadeLocal eventInfoFacade;
    @EJB
    private EventLibraryFacadeLocal eventLibraryFacade;   
    
    /**
     *@UpdateEventEJB.updateEvent : update an event record in EventLibrary table by EventId(Primary key)
     * @param jsonstr     
     * @return boolean      
     */
    @Override
    public boolean updateEvent(String jsonstr) {
        try {
            JSONObject json = JsonModel.JsonDecoder(jsonstr);            
            EventLibrary el = JsonModel.eventMessageReader(json);
            EventInfo ei = JsonModel.eventInfoReader(json);
            int eventId = el.getEventId();
            String name = el.getName();
            String des = el.getDescription();
            String type = el.getEventType();
            Date start = el.getTimeStart();
            Date end = el.getTimeEnd();
            String avatar = ei.getAvatarImg();
            String shortdes = ei.getEventShortDesc();
            String address = ei.getAddress();
            return eventInfoFacade.updateEvent(eventId,name,des,type,start,end,avatar,shortdes,address);            
        } catch (Exception e) {                       
            System.out.println(e.getMessage());
            return false;            
        }
    }

    
}
